﻿// Copyright (c) 2014 Converter Systems LLC

using ConverterSystems.Workstation.Infrastructure;
using MahApps.Metro;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Windows;

namespace ConverterSystems.Workstation.ViewModels
{
    /// <summary>
    /// A view model for Shell.
    /// </summary>
    [Export]
    public class ShellViewModel : NavigationViewModelBase
    {
        private Accent _selectedAccent;
        private AppTheme _selectedTheme;

        public ShellViewModel()
        {
            AppThemes = ThemeManager.AppThemes.ToList();
            Accents = ThemeManager.Accents.ToList();

            var current = ThemeManager.DetectAppStyle();
            if (current != null)
            {
                _selectedTheme = current.Item1;
                _selectedAccent = current.Item2;
            }
            else
            {
                _selectedTheme = ThemeManager.GetAppTheme("BaseLight");
                _selectedAccent = ThemeManager.GetAccent("Blue");
            }
        }

        public IEnumerable<AppTheme> AppThemes { get; private set; }

        public AppTheme SelectedTheme
        {
            get { return _selectedTheme; }
            set
            {
                SetProperty(ref _selectedTheme, value);
                ThemeManager.ChangeAppStyle(Application.Current, _selectedAccent, _selectedTheme);
            }
        }

        public IEnumerable<Accent> Accents { get; private set; }

        public Accent SelectedAccent
        {
            get { return _selectedAccent; }
            set
            {
                SetProperty(ref _selectedAccent, value);
                ThemeManager.ChangeAppStyle(Application.Current, _selectedAccent, _selectedTheme);
            }
        }
    }
}